<?php
/**
 * 招生管理爬虫
 *
 */

namespace console\spider;


use console\spider\utils\HttpClient;
use console\spider\utils\TimeUtils;

class ZSGLSpider
{

    /**
     * 爬取招生计划审核
     * @param $schoolId
     */
    public static function getEnrollmentPlanInfo($school)
    {
        $params = Array();
        $params['dir'] = Params::enrollmentPlanDir;
        $url = Params::enrollmentPlanIfoUrl."&nd=".TimeUtils::gettimestamp()."&zsjhShQB.id=$school->id&pqb.pagingInfo.pageNum=";
        $params['fileName'] = $school->xxjgmc;
        $params['tag']= $school->xxjgmc;
        HttpClient::dataSave($url,$params);
    }

    /**
     * 爬取招生计划审核
     */
    public static function getEnrollmentPlan()
    {
        $pageNum = 0;
        do{
            $pageNum++;
            try {
                $data = HttpClient::request(Params::enrollmentPlanUrl. $pageNum);
                $enrollmentPlanJson = json_decode($data['content']);
                $totalPages = $enrollmentPlanJson->pagingInfo->totalPages;
                echo "招生计划审核：totolPages: $totalPages pageNum: $pageNum \n";
                foreach ($enrollmentPlanJson->resultList as $school){
                    self::getEnrollmentPlanInfo($school);
                }
            } catch (Exception $e) {
                echo $e;
                break;
            }
        }while($pageNum < $totalPages);
    }
}